using System.Collections.Generic;
using UnityEngine;

namespace BCWAccountVip
{
	public class AccountVipBonusChanger
	{
		private static AccountVipBonusChanger instance;

		private List<string> _chestsId = new List<string>();

		private AccountVipBonusChanger()
		{
			List<Product> products = MarketController.Instance.GetProducts("Hidden", "Hidden");
			List<ProductChest> list = new List<ProductChest>();
			foreach (Product item in products)
			{
				if (item is ProductChest)
				{
					list.Add((ProductChest)item);
				}
			}
			list.Sort(delegate(ProductChest x, ProductChest y)
			{
				if (x.priorityInVip < y.priorityInVip)
				{
					return -1;
				}
				return (x.priorityInVip != y.priorityInVip) ? 1 : 0;
			});
			foreach (ProductChest item2 in list)
			{
				_chestsId.Add(item2.id);
			}
		}

		public static AccountVipBonusChanger GetInstance()
		{
			if (instance == null)
			{
				instance = new AccountVipBonusChanger();
			}
			return instance;
		}

		public SessionReputationReward ModifyReward(SessionReputationReward reward)
		{
			SessionReputationReward sessionReputationReward = (SessionReputationReward)reward.Clone();
			int num = _chestsId.IndexOf(reward.rewardID);
			if (reward.type.Equals(SessionReputationRewardType.Star))
			{
				sessionReputationReward.rewardCount = Mathf.Max(reward.rewardCount, Mathf.CeilToInt((float)reward.rewardCount * 1.5f));
			}
			else if (reward.type.Equals(SessionReputationRewardType.Cash))
			{
				sessionReputationReward.rewardCount = Mathf.Max(reward.rewardCount, Mathf.CeilToInt((float)reward.rewardCount * 2f));
			}
			else if (num != -1)
			{
				if (num + 1 < _chestsId.Count)
				{
					sessionReputationReward.rewardID = _chestsId[num + 1];
				}
				else
				{
					sessionReputationReward.rewardCount = reward.rewardCount + 1;
				}
			}
			return sessionReputationReward;
		}

		public InfoMatchReward ModifyReward(InfoMatchReward reward)
		{
			InfoMatchReward result = default(InfoMatchReward);
			result.id = reward.id;
			result.weight = reward.weight;
			result.count = reward.count;
			int num = _chestsId.IndexOf(reward.id);
			if (reward.id == "star")
			{
				result.id = reward.id;
				result.weight = reward.weight;
				result.count = Mathf.Max(reward.count, Mathf.CeilToInt((float)reward.count * 1.5f));
			}
			else if (reward.id == "cash")
			{
				result.id = reward.id;
				result.weight = reward.weight;
				result.count = Mathf.Max(reward.count, Mathf.CeilToInt((float)reward.count * 2f));
			}
			else if (num != -1)
			{
				if (num + 1 < _chestsId.Count)
				{
					result.id = _chestsId[num + 1];
				}
				else
				{
					result.count = reward.count + 1;
				}
			}
			return result;
		}
	}
}
